package com.googlecode.imanager.core.base;

import java.io.OutputStream;

import com.googlecode.imanager.client.Application;
import com.googlecode.imanager.client.Control;
import com.googlecode.imanager.client.Document;
import com.googlecode.imanager.client.bridge.BridgeType;
import com.googlecode.imanager.client.io.HttpRequest;
import com.googlecode.imanager.client.style.Theme;
import com.googlecode.imanager.client.style.listener.StyleAttribute;
import com.googlecode.imanager.client.style.listener.StyleWrapper;
import com.googlecode.imanager.client.util.Dimension;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class EmptyApplication extends BridgeApplication {

    // TODO desamarrar e transformar em singleton
    private static EmptyControl emptyControl;
    
    public EmptyApplication(DefaultManager manager) {
        this(manager, null, null);
    }
    
    public EmptyApplication(DefaultManager manager, Application application, OutputStream output) {
        super(manager, application, null);
        
        if (emptyControl == null){
            emptyControl = new EmptyControl(this);
        }
    }

    @Override
    public BridgeType getImplementationType() {
        return BridgeType.EMPTY;
    }

    @Override
    public BridgeControl createImplementation(Control source) {
        getManager().setImpl(source, emptyControl);
        return emptyControl;
    }

    @Override
    protected void generateBridgePrint(Document document) throws Exception {
        // nothing to do
    }

    @Override
    protected void destroy() {
        // nothing to do
    }

    @Override
    public Dimension getScreenSize() {
        // TODO pegar a dimensão da Bridge em execução
        return new Dimension(0, 0);
    }

    @Override
    public void handleError(Throwable e) {
        e.printStackTrace();
    }

    @Override
    public void httpCall(HttpRequest request) {
        request.onFailure(new UnsupportedOperationException());
    }

    @Override
    public void showErrorDialog(String title, String message, Throwable e) {
    }

    @Override
    public String showInputDialog(String title, String message) {
        return null;
    }

    @Override
    public void showMessageDialog(String title, String message) {
    }

    @Override
    public boolean showQuestionDialog(String title, String message) {
        return false;
    }

    @Override
    public void showWarningDialog(String title, String message) {
    }

    @Override
    public void loadImageContent(DefaultImage abstractImage) {
    }

    @Override
    public void add(Document document) {
    }

    @Override
    public void remove(Document document) {
    }

    @Override
    public boolean isFireStyleChangesToChildren() {
        return false;
    }

    @Override
    public void onThemeAttach(Theme theme) {
    }

    @Override
    public void onThemeDetach(Theme theme) {
    }

    @Override
    public <T> void onStyleAttributeChanged(StyleWrapper styleWrapper,
            StyleAttribute<T> attribute, T attributeValue) {
    }

}
